/*!
 * Copyright (C) 2020 - All Rights Reserved by
 * @author : ZhaoYanbo
 * @email  : zyb920@hotmail.com
 * @created: 2020-10-31
 * @version: 1.0.0.0
 *
 */

#ifndef LE_COMMAND_H
#define LE_COMMAND_H

#include "LyricEditData.h"
#include <QList>

class LyricEditWidget;
class LE_Command;

///命令管理器(LE = Lyric&&Edit)
class LE_CommandInvok final
{
public:
    LE_CommandInvok(){}
    ~LE_CommandInvok();

    void push(LE_Command *ptr);
    void redo();
    void undo();
    void clear();

    bool canUndo() const;
    bool canRedo() const;

private:
    void clearUndo();
    void clearRedo();

    QList<LE_Command *> m_redo_list;
    QList<LE_Command *> m_undo_list;
};

class LE_Command
{
public:
    enum Type{Move, CanMove, Preview, Zoom};
    LE_Command(LyricEditWidget *wPtr) {
        p_receiver = wPtr;
    }

    virtual ~LE_Command(){
        p_receiver = nullptr;
    }

    Type type() const {
        return m_type;
    }

    virtual void redo() = 0;
    virtual void undo() = 0;

protected:
    Type m_type;
    LyricEditWidget *p_receiver = nullptr;
};

class LE_MoveCommand final : public LE_Command
{
public:
    LE_MoveCommand(const QVector<VPos> &oldPos, const QVector<VPos> &newPos, LyricEditWidget *wPtr);

    void redo() override;
    void undo() override;

private:
    QVector<VPos> m_oldPos;
    QVector<VPos> m_newPos;
};

///点击canmove
class LE_CanMoveCommand final : public LE_Command
{
public:
    LE_CanMoveCommand(int index, LyricEditWidget *wPtr);
    ~LE_CanMoveCommand(){}

    void redo() override;
    void undo() override;

private:
    int  m_index;
    bool m_bCanmove;
};

///点击preview
class LE_PreviewCommand final : public LE_Command
{
public:
    LE_PreviewCommand(int oldIndex, int newIndex, LyricEditWidget *wPtr);
    ~LE_PreviewCommand(){}

    void redo() override;
    void undo() override;

private:
    int m_oldIndex;
    int m_newIndex;
};

class LE_ZoomCommand final : public LE_Command
{
public:
    ///
    /// \brief LE_ZoomCommand
    /// \param in true:放大 false:缩小
    /// \param wPtr
    ///
    LE_ZoomCommand(bool in, LyricEditWidget *wPtr);
    ~LE_ZoomCommand(){}

    void undo() override;
    void redo() override;

private:
    bool m_isZoomIn;
};

#endif // LE_COMMAND_H
